//
//  GJMainViewController.m
//  GJLifeSimple
//
//  Created by 杨帆 on 16/6/17.
//  Copyright © 2016年 GoodJob. All rights reserved.
//

#import "GJMainViewController.h"
#import "GJNavigationController.h"
#import "CZNetworkManager.h"
#import "GJCircleModel.h"

@interface GJMainViewController ()

@end

@implementation GJMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor cyanColor];
    
    [self addChildViewControllers];
    
    [self homeLogin];
}

/**
 *  登录接口
 */
- (void)login {
    
    NSDictionary *parameters = @{@"account": @"13800111100",@"pasword": @"123456"};
    
    
    [[CZNetworkManager sharedManager] loginWithURLString:@"http://iosapi.itcast.cn/life/loginData.json.php" parameters:parameters completion:^(id responseObject) {
        //结果,字典
        //gender = 1;
//        mobile = 13800111100;
//        nick_name = Ricky;
//        remember_me = 123;
//        user_id = 123456;
//        user_name = Ricky;
//        small_avatar =  http://iosapi.itcast.cn/life/images/small_14477475387400.jpg;
//        middle_avatar =  http://iosapi.itcast.cn/life/images/middle_14477475387400.jpg;

        NSLog(@"%@", responseObject);
    }];
}

/**
 *  首页
 */
- (void)homeLogin {
    
    NSDictionary *dict = @{@"anu": @"api/1/index/get_index_info"};
    
    [[CZNetworkManager sharedManager] PostListWithURLString:@"http://iosapi.itcast.cn/life/homeData.json.php" parameters:dict completion:^(id data, NSError *error) {

        NSLog(@">>>%@,error = %@", data[@"group"], error);
        
        NSArray <GJCircleModel *>*array = [NSArray yy_modelArrayWithClass:[GJCircleModel class] json:data[@"group"][@"list"]];
        
        NSLog(@"%@", array);
        
    }];
    
}

/**
 *  商品详情
 */
- (void)shopFoodList {
//     NSNumber *n =[NSNumber numberWithInt:3];
//    NSDictionary *dict = @{@"good_id": [NSNumber numberWithInt:3]};
    
    [[CZNetworkManager sharedManager] PostListWithURLString:@"http://iosapi.itcast.cn/life/good_info.json.php" parameters:nil completion:^(id data, NSError *error) {
        
        NSLog(@">>>%@,error = %@", data, error);
        
    }];
    
}

/**
 *  商家详情
 */

- (void)shopDetail {
    
    
    [[CZNetworkManager sharedManager] PostListWithURLString:@"http://iosapi.itcast.cn/life/shop_info.json.php" parameters:nil completion:^(id data, NSError *error) {
        
        NSLog(@">>>%@,error = %@", data, error);
        
    }];
}

/**
 *  圈子数据
 */
- (void)circleList {
    
    NSDictionary *dict = @{@"anu": @"api/1/index/get_index_info"};
    [[CZNetworkManager sharedManager] PostListWithURLString:@"http://iosapi.itcast.cn/life/circleData.json.php" parameters:dict completion:^(id data, NSError *error) {
        
        NSLog(@">>>%@,error = %@", data, error);
        
    }];
    
}
/**
 *  工具
 */
- (void)tool {
    
    NSDictionary *dict = @{@"anu": @"api/1/index/get_index_info"};
    [[CZNetworkManager sharedManager] PostListWithURLString:@"http://iosapi.itcast.cn/life/circleData.json.php" parameters:dict completion:^(id data, NSError *error) {
        
        NSLog(@">>>%@,error = %@", data, error);
        
    }];
}

- (void)addChildViewControllers {
    
    NSArray *array = @[
                       @{@"clsName": @"GJHomeViewController", @"title": @"首页", @"imageName": @"tabbar1"},
                        @{@"clsName": @"GJNewsViewController", @"title": @"新闻", @"imageName": @"新闻"},
                       @{@"clsName": @"GJMoreViewController", @"title": @"更多", @"imageName": @"更多"},
                       @{@"clsName": @"GJLifeViewController", @"title": @"圈子", @"imageName": @"圈子"},
                       @{@"clsName": @"GJOurViewController", @"title": @"我们", @"imageName": @"我们"},
                       ];
    
    NSMutableArray *arrayM = [NSMutableArray array];
    
    for (NSDictionary *dict in array) {
        
        [arrayM addObject:[self addChildViewControllerWithDict:dict]];
        
    }
    
    self.viewControllers = arrayM.copy;
}


//添加单个控制器
- (UIViewController *)addChildViewControllerWithDict:(NSDictionary *)dict {
    
    NSString *clsName = dict[@"clsName"];
    
    Class cls = NSClassFromString(clsName);
    
    NSAssert(cls != nil, @"类名错误");
    
    UIViewController *vc = [cls new];
    
    vc.title = dict[@"title"];
    
    NSString *imageName = dict[@"imageName"];
    
    NSString *imageMore = [imageName stringByAppendingString:@"默认"];
    vc.tabBarItem.image = [UIImage imageNamed:imageMore];
    
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    return [[UINavigationController alloc] initWithRootViewController:vc];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
